
// pipfreeze.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  const char *python_exec = "python3"; // 默认解释器
  const char *output_file = "requirements.txt";

  if (argc >= 2) {
    python_exec = argv[1];
  }
  if (argc >= 3) {
    output_file = argv[2];
  }
  if (argc == 1) {
    printf("using default configuration.\n");
    printf("you can change it by passing arguments in the following format:\n");
    printf("%s [python_exec] [output_file]\n", *argv);
  }

  char command[512];
  snprintf(command, sizeof(command), "%s -m pip freeze > \"%s\"", python_exec,
           output_file);

  int ret = system(command);
  if (ret != 0) {
    fprintf(stderr, "Failed to run pip freeze via: %s\n", python_exec);
    return ret;
  }

  printf("✅ Saved to %s using %s\n", output_file, python_exec);
  return 0;
}
